package tools

import (
    "context"
    "fmt"
    "os"
    "strings"

    "weekly-report/types"
)

func ExportMarkdown(ctx context.Context, report *types.WeeklyReport) (string, error) {
    md := fmt.Sprintf(`# 本周周报（%s）

## 概述
%s

## 主要成果
%s

## 问题与风险
%s

## 下周计划
%s

## 关键指标
`, report.Week, report.Summary,
        "- "+strings.Join(report.KeyAchievements, "\n- "),
        "- "+strings.Join(report.Issues, "\n- "),
        "- "+strings.Join(report.NextWeekPlan, "\n- "))

    file := fmt.Sprintf("weekly_%s.md", report.Week)
    err := os.WriteFile(file, []byte(md), 0644)
    return file, err
}
